﻿using AmiCheckin.UI.ViewModels;
using System.Windows;
using System.Windows.Controls;

namespace AmiCheckin.UI.Views
{
    public partial class RewardLocationsView : UserControl
    {
        public RewardLocationsView()
        {
            InitializeComponent();
        }

        private void RewardLocationsView_OnLoaded(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Load();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Save();
            MessageBox.Show("保存成功~请手动重载config.json");

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ViewModel.LocationObjects.Add(new()
            {
                Name = "新增配置"
            });
        }

        private void Button_AddArg(object sender, RoutedEventArgs e)
        {
            if (InputDialog.GetInput(out var input))
            {
                (ListBox.SelectedItem as RewardLocationObject).Args.Add(input);
            }
        }

        private void Button_DelArg(object sender, RoutedEventArgs e)
        {
            if (ArgsListBox.SelectedIndex != -1)
                (ListBox.SelectedItem as RewardLocationObject).Args.RemoveAt(ListBox.SelectedIndex);
        }
    }
}